<?php

class StatisticsController extends Controller
{
	public $layout="//layouts/nolayout";
	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		//base
	}

	/**
	 * This is the default 'index' action that is invoked
	 * when an action is not explicitly requested by users.
	 */
	
	public function actionVirtualExperimentStatisticsPage()
	{
		$this->render('VirtualExperimentStatisticsPage');
	}
	
	
	public function actionGetVirtualExperimentStatistics($tid)
	{
		$json=array();
		$weekList=Week::model()->findAll();
		$datas=array();
		
		for ($i=0;$i<count($weekList);$i++)
		{
			$elem=array();
			$elem['name']=$weekList[$i]->week_describe;
			
			$appointments=Appointment::model()->findAllByAttributes(array('term_id'=>$tid,'week_id'=>$weekList[$i]->week_id));
			$elem['data']=count($appointments);
			$roomList=Room::model()->findAll();
			$elem['detail']='';
			for ($j=0;$j<count($roomList);$j++)
			{
				$roomDetail=Appointment::model()->findAllByAttributes(
					array(
					'term_id'=>$tid,
					'week_id'=>$weekList[$i]->week_id,
					'room_id'=>$roomList[$j]->room_id)
				);
				if (count($roomDetail)!=0)
					$elem['detail']=$elem['detail'].$roomList[$j]->name.':'.count($roomDetail).'人次<br>';
			}
			array_push($datas,$elem);
		}
		$json['data'] = $datas;
		echo CJSON::encode($json);
	}
}